package com.llc.mall.user.interfaces.app;

import com.llc.mall.user.application.query.service.AreaQueryService;
import com.llc.mall.user.interfaces.vo.AreaVo;
import com.llc.mall.common.core.response.ServerResponseEntity;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 省市区地区信息管理接口
 */
@Tag(name = "全国地区信息")
@RequestMapping("/api/v1/areas")
@RestController
public class AreaController {

    @Resource
    private AreaQueryService areaQueryService;

    /**
     * 获取完整的地区层级树结构
     *
     * @return 包含完整地区树结构的响应实体
     */
    @Operation(summary = "获取全量地区树", description = "返回完整的省-市-区三级树形结构数据")
    @GetMapping
    public ServerResponseEntity<List<AreaVo>> getFullRegionTree() {
        List<AreaVo> regionTree = areaQueryService.getAreaListInfo();
        return ServerResponseEntity.success(regionTree);
    }

    /**
     * 根据父级区域ID获取直接子区域列表
     *
     * @param parentId 父级区域标识符（路径参数）
     * @return 包含子区域列表的响应实体
     */
    @Operation(summary = "获取子区域列表",
            description = "根据父区域ID查询其直接下级区域列表",
            parameters = @Parameter(name = "parentId", description = "父级区域ID", required = true))
    @GetMapping("/{parentId}/children")
    public ServerResponseEntity<List<AreaVo>> getChildrenByParentId(@PathVariable("parentId") Long parentId) {
        List<AreaVo> children = areaQueryService.listByPid(parentId);
        return ServerResponseEntity.success(children);
    }

}

